package cn.livingCloud.dto;

import cn.livingCloud.entity.content.Button;
import cn.livingCloud.utils.DateUtils;
import cn.livingCloud.wechat.entity.ButtonType;
import cn.livingCloud.wechat.entity.WechatButton;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by sujiantang on 2016/1/6.
 */
public class ButtonDto {

    private String uuid;

    private String name;

    private ButtonType type;

    private String key;

    private String url;

    private String createTime;

    private String parentId;

    private List<ButtonDto> subButtonList = new ArrayList<>();

    private boolean showAddSub = false;

    public ButtonDto(Button button) {
        this.uuid = button.getUuid();
        this.name = button.getName();
        this.type = button.getType();
        this.key = button.getKey();
        this.url = button.getUrl();
        this.createTime = DateUtils.toDateText(button.getCreateTime()
                , DateUtils.DEFAULT_DATE_TIME_FORMAT);
        this.parentId = button.getParentId();
        for (WechatButton wechatButton : button.getSub_button()) {
            Button subButton = (Button) wechatButton;
            subButtonList.add(new ButtonDto(subButton));
        }
        if (subButtonList.size() < 5) {
            this.showAddSub = true;
        }
    }

    public String getUuid() {
        return uuid;
    }

    public ButtonDto setUuid(String uuid) {
        this.uuid = uuid;
        return this;
    }

    public String getName() {
        return name;
    }

    public ButtonDto setName(String name) {
        this.name = name;
        return this;
    }

    public ButtonType getType() {
        return type;
    }

    public ButtonDto setType(ButtonType type) {
        this.type = type;
        return this;
    }

    public String getKey() {
        return key;
    }

    public ButtonDto setKey(String key) {
        this.key = key;
        return this;
    }

    public String getUrl() {
        return url;
    }

    public ButtonDto setUrl(String url) {
        this.url = url;
        return this;
    }

    public String getShortUrl() {
        if (url.length() > 53) {
            return url.substring(0, 50) + "...";
        }
        return url;
    }

    public String getCreateTime() {
        return createTime;
    }

    public ButtonDto setCreateTime(String createTime) {
        this.createTime = createTime;
        return this;
    }

    public String getParentId() {
        return parentId;
    }

    public ButtonDto setParentId(String parentId) {
        this.parentId = parentId;
        return this;
    }

    public List<ButtonDto> getSubButtonList() {
        return subButtonList;
    }

    public ButtonDto setSubButtonList(List<ButtonDto> subButtonList) {
        this.subButtonList = subButtonList;
        return this;
    }

    public boolean isShowAddSub() {
        return showAddSub;
    }

    public ButtonDto setShowAddSub(boolean showAddSub) {
        this.showAddSub = showAddSub;
        return this;
    }
}
